home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / contrib / pdcurs22 / src / portable / termattr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-26  |  12.6 KB  |  412 lines

  1. /*
  2. ***************************************************************************
  3. * This file comprises part of PDCurses. PDCurses is Public Domain software.
  4. * You may use this code for whatever purposes you desire. This software
  5. * is provided AS IS with NO WARRANTY whatsoever.
  6. * Should this software be used in another application, an acknowledgement
  7. * that PDCurses code is used would be appreciated, but is not mandatory.
  8. *
  9. * Any changes which you make to this software which may improve or enhance
  10. * it, should be forwarded to the current maintainer for the benefit of 
  11. * other users.
  12. *
  13. * The only restriction placed on this code is that no distribution of
  14. * modified PDCurses code be made under the PDCurses name, by anyone
  15. * other than the current maintainer.
  16. * See the file maintain.er for details of the current maintainer.
  17. ***************************************************************************
  18. */
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <limits.h>
  22. #define    CURSES_LIBRARY    1
  23. #include <curses.h>
  24. #ifdef UNIX
  25. #include <defs.h>
  26. #include <term.h>
  27. #endif
  28.  
  29. /* undefine any macros for functions defined in this module */
  30. #undef    baudrate
  31. #undef    erasechar
  32. #undef    has_ic
  33. #undef    has_il
  34. #undef    killchar
  35. #undef    longname
  36. #undef    termattrs
  37. #undef    termname
  38. #undef    wordchar
  39.  
  40. /* undefine any macros for functions called by this module if in debug mode */
  41. #ifdef PDCDEBUG
  42. #endif
  43.  
  44. #ifdef PDCDEBUG
  45. char *rcsid_termattrs  = "$Id$";
  46. #endif
  47.  
  48. /*man-start*********************************************************************
  49.  
  50.   Name:                                                     termattrs
  51.  
  52.   Synopsis:
  53.       int baudrate(void);
  54.       char erasechar(void);
  55.       bool has_ic(void);
  56.       bool has_il(void);
  57.       char killchar(void);
  58.       char *longname(void);
  59.       chtype termattrsr(void);
  60.       char *termname(void);
  61.  
  62.       char    wordchar(void);
  63.  
  64.   X/Open Description:
  65.      baudrate() returns the output speed of the terminal.  The number 
  66.      returned is bits per second, for example 9600, and is an integer.
  67.  
  68.      The user's current ERASE character is returned from a call to
  69.      erasechar();
  70.  
  71.      The has_ic function will return TRUE if the terminal has insert 
  72.      character and delete character capabilities.
  73.  
  74.      The has_il() function will return TRUE if the terminal has insert
  75.      line and delete line capabilities.
  76.  
  77.      The user's current KILL character is returned from a call to
  78.      killchar();
  79.  
  80.      longname() returns a pointer to a static area containing a
  81.      verbose description of the current terminal.  The maximum length
  82.      of the string is 128 characters.  It is defined only after the
  83.      call to initscr() or newterm().  The area is overwritten by each
  84.      call to newterm() and is not restored by set_term().  The value
  85.      should therefore be saved between calls to newterm(), if
  86.      longname() is going to be used with multiple terminals.
  87.  
  88.      termname() returns a pointer to a static area containing a
  89.      short description of the current terminal (14 characters).
  90.  
  91.      termattrs() returns a logical OR of all video attributes
  92.      supported by the terminal.
  93.  
  94.   PDCurses Description:
  95.      If FAST_VIDEO is true, then this is the largest possible
  96.      (portable) int value (INT_MAX from limits.h) IF direct
  97.      video is possible, OR the approximate guess at BIOS speeds,
  98.      19200.
  99.      If FAST_VIDEO is false, this is an approximate guess at BIOS
  100.      speeds, 19200.
  101.  
  102.      erasechar(), killchar() and wordchar() all return values that are 
  103.      hardcoded at this time.  There may be future development
  104.      to allow applications an easy way to specify these value.
  105.  
  106.      For DOS, has_ic() and has_il() always return TRUE, as the speed of
  107.      the DIRECT VIDEO or even BIOS writes is quicker than on a
  108.      serial terminal.
  109.      For FLEXOS, this value has meaning and depends on the terminal,
  110.      though at this time, it is a constant TRUE.
  111.  
  112.      In addition to the above definition for longname(), the form of 
  113.      this string is the adapter name (or video card name) and the text 
  114.      resolution. This may also be followed by the notation that the video 
  115.      card may be a clone, which indicates that the card identification
  116.      maps to more than one unique card.
  117.      e.g. The MDS Genius and the Quadram QuadHPG identify themselves
  118.      in the same manner, but are vastly different in maximum resolution.
  119.  
  120.      The user's current WORD character is returned from a call to
  121.      wordchar();
  122.  
  123.   X/Open Return Value:
  124.      All functions return OK on success and ERR on error.
  125.  
  126.   X/Open Errors:
  127.      No errors are defined for this function.
  128.  
  129.   Portability                             X/Open    BSD    SYS V
  130.                                           Dec '88
  131.       baudrate                              Y        Y       Y
  132.       erasechar                             Y        Y       Y
  133.       has_ic                                Y        Y       Y
  134.       has_il                                Y        Y       Y
  135.       killchar                              Y        Y       Y
  136.       longname                              Y        Y       Y
  137.       termattrs                             Y        Y       Y
  138.       termname                              Y        Y       Y
  139.       wordchar                              -        -       -
  140.  
  141. **man-end**********************************************************************/
  142.  
  143. #ifdef    FLEXOS
  144. extern    char*    _flexos_gname();
  145. #endif
  146. static    char    _display[ 128 ];
  147. static    char    _shrtnme[ 14 ];
  148.  
  149. /***********************************************************************/
  150. int    baudrate(void)
  151. /***********************************************************************/
  152. {
  153. #ifdef PDCDEBUG
  154.     if (trace_on) PDC_debug("baudrate() - called\n");
  155. #endif
  156.  
  157. #ifdef UNIX
  158.     return (_CUR_TERM.baudrate);
  159. #else
  160. #ifdef FAST_VIDEO
  161.     return (_cursvar.direct_video ? INT_MAX : 19200 );
  162. #else
  163.     return (19200);            /* Approx. guess at BIOS speeds.*/
  164. #endif
  165. #endif
  166. }
  167. /***********************************************************************/
  168. char    erasechar(void)
  169. /***********************************************************************/
  170. {
  171. #ifdef PDCDEBUG
  172.     if (trace_on) PDC_debug("erasechar() - called\n");
  173. #endif
  174.  
  175. #ifdef UNIX
  176. #ifdef USE_TERMIO
  177.     ioctl(_CUR_TERM.fd, TCGETA, &_CUR_TERM.prog_mode);
  178.     return(_CUR_TERM.prog_mode.c_cc[VERASE]);
  179. #else
  180.     ioctl(_CUR_TERM.fd, TIOCGETP, &_CUR_TERM.prog_mode.v6);
  181.     return(_CUR_TERM.prog_mode.v6.sg_erase);
  182. #endif
  183. #else
  184.     return(    _ECHAR );    /* character delete char (^H) */
  185. #endif
  186. }
  187. /***********************************************************************/
  188. bool    has_ic(void)
  189. /***********************************************************************/
  190. {
  191. #ifdef PDCDEBUG
  192.     if (trace_on) PDC_debug("has_ic() - called\n");
  193. #endif
  194.  
  195. #ifdef UNIX
  196.     if (insert_character != NULL && delete_character != NULL)
  197.         return(TRUE);
  198.     else
  199.         return(FALSE);
  200. #else
  201.     return( TRUE );
  202. #endif
  203. }
  204. /***********************************************************************/
  205. bool    has_il(void)
  206. /***********************************************************************/
  207. {
  208. #ifdef PDCDEBUG
  209.     if (trace_on) PDC_debug("has_il() - called\n");
  210. #endif
  211.  
  212. #ifdef UNIX
  213.     if (insert_line != NULL && delete_line != NULL)
  214.         return(TRUE);
  215.     else
  216.         return(FALSE);
  217. #else
  218.     return( TRUE );
  219. #endif
  220. }
  221. /***********************************************************************/
  222. char    killchar(void)
  223. /***********************************************************************/
  224. {
  225. #ifdef PDCDEBUG
  226.     if (trace_on) PDC_debug("killchar() - called\n");
  227. #endif
  228.  
  229. #ifdef UNIX
  230. #ifdef USE_TERMIO
  231.     ioctl(_CUR_TERM.fd, TCGETA, &_CUR_TERM.prog_mode);
  232.     return(_CUR_TERM.prog_mode.c_cc[VKILL]);
  233. #else
  234.     ioctl(_CUR_TERM.fd, TIOCGETP, &_CUR_TERM.prog_mode.v6);
  235.     return(_CUR_TERM.prog_mode.v6.sg_kill);
  236. #endif
  237. #else
  238.     return( _DLCHAR );    /* line delete char (^U) */
  239. #endif
  240. }
  241. /***********************************************************************/
  242. char*    longname(void)
  243. /***********************************************************************/
  244. {
  245. #ifdef PDCDEBUG
  246.     if (trace_on) PDC_debug("longname() - called\n");
  247. #endif
  248.  
  249. #if defined (XCURSES)
  250.     if (_cursvar.mono)
  251.         sprintf(_display,"XWINDOWS-MONO-%dx%d",LINES,COLS);
  252.     else
  253.         sprintf(_display,"XWINDOWS-COLOR-%dx%d",LINES,COLS);
  254. #endif
  255.  
  256. #ifdef OS2
  257. # ifdef EMXVIDEO
  258.     switch (_cursvar.mono)
  259.     {
  260.     case FALSE:    sprintf(_display,"COLOR-%dx%d", LINES, COLS); break;
  261.     case TRUE:    sprintf(_display,"MONO-%dx%d", LINES, COLS); break;
  262. # else
  263.     switch    (_cursvar.adapter.adapter)
  264.     {
  265.     case DISPLAY_CGA:    sprintf(_display, "CGA-%dx%d", LINES, COLS);      break;
  266.     case DISPLAY_MONOCHROME:    sprintf(_display, "MDA-%dx%d", LINES, COLS);      break;
  267.     case DISPLAY_EGA:    sprintf(_display, "EGA-%dx%d", LINES, COLS); break;
  268.     case DISPLAY_VGA:    sprintf(_display, "VGA-%dx%d", LINES, COLS); break;
  269.     case DISPLAY_8514A:     sprintf(_display, "8514-%dx%d", LINES, COLS);  break;
  270. # endif
  271.     default:    sprintf(_display, "Unknown-%dx%d", LINES, COLS);  break;
  272.     }
  273. #endif
  274.  
  275. #ifdef DOS
  276.     switch    (_cursvar.adapter)
  277.     {
  278.     case _CGA:    sprintf(_display, "CGA-%dx%d", LINES, COLS);      break;
  279.     case _MDA:    sprintf(_display, "MDA-%dx%d", LINES, COLS);      break;
  280.     case _EGACOLOR:    sprintf(_display, "EGAColor-%dx%d", LINES, COLS); break;
  281.     case _EGAMONO:    sprintf(_display, "EGAMono-%dx%d", LINES, COLS);  break;
  282.     case _VGACOLOR:    sprintf(_display, "VGAColor-%dx%d", LINES, COLS); break;
  283.     case _VGAMONO:    sprintf(_display, "VGAMono-%dx%d", LINES, COLS);  break;
  284.     case _MCGACOLOR:sprintf(_display, "MCGAColor-%dx%d", LINES, COLS);break;
  285.     case _MCGAMONO:    sprintf(_display, "MCGAMono-%dx%d", LINES, COLS); break;
  286.     case _MDS_GENIUS:sprintf(_display, "Genius-%dx%d", LINES, COLS);  break;
  287.     default:    sprintf(_display, "Unknown-%dx%d", LINES, COLS);  break;
  288.     }
  289. #endif
  290.  
  291. #ifdef    FLEXOS
  292.     switch    (_cursvar.adapter)
  293.     {
  294.     case _FLEXOS:    sprintf(_display, "%s", _cursesgname());      break;
  295.     default:    sprintf(_display, "Unknown-%dx%d", LINES, COLS);  break;
  296.     }
  297. #endif
  298.  
  299.  
  300.     if (_cursvar.bogus_adapter)
  301.         strcat(_display, " (Clone)");
  302.  
  303.     return (_display);
  304. }
  305. /***********************************************************************/
  306. chtype    termattrs(void)
  307. /***********************************************************************/
  308. {
  309. #if defined (XCURSES)
  310.     chtype temp =   (A_NORMAL | A_BOLD); /* X cannot blink */
  311. #else
  312.     chtype temp =   (A_NORMAL | A_BOLD) | A_BLINK;
  313. #endif
  314.  
  315. #ifdef PDCDEBUG
  316.     if (trace_on) PDC_debug("termattrs() - called\n");
  317. #endif
  318.  
  319.     if( ! _cursvar.mono )
  320.         temp |= A_COLOR;
  321.  
  322.     if( COLORS < 1 )
  323.         temp |= A_REVERSE;
  324.  
  325.     return( temp );
  326. }
  327. /***********************************************************************/
  328. char*    termname(void)
  329. /***********************************************************************/
  330. {
  331. #ifdef PDCDEBUG
  332.     if (trace_on) PDC_debug("termname() - called\n");
  333. #endif
  334.  
  335. #if defined (XCURSES)
  336.     if (_cursvar.mono)
  337.         sprintf(_shrtnme,"X-MONO");
  338.     else
  339.         sprintf(_shrtnme,"X-COLOR");
  340. #endif
  341.  
  342. #ifdef     OS2
  343. # ifdef    EMXVIDEO
  344.     switch (_cursvar.mono)
  345.     {
  346.     case FALSE:    sprintf(_shrtnme,"COLOR"); break;
  347.     case TRUE:    sprintf(_shrtnme,"MONO"); break;
  348. # else
  349.     switch    (_cursvar.adapter.adapter)
  350.     {
  351.     case DISPLAY_CGA:    sprintf(_shrtnme, "CGA");      break;
  352.     case DISPLAY_MONOCHROME:    sprintf(_shrtnme, "MDA");      break;
  353.     case DISPLAY_EGA:    sprintf(_shrtnme, "EGA"); break;
  354.     case DISPLAY_VGA:    sprintf(_shrtnme, "VGA"); break;
  355.     case DISPLAY_8514A:     sprintf(_shrtnme, "8514");  break;
  356. # endif
  357.     default:    sprintf(_shrtnme, "Unknown");  break;
  358.     }
  359. #endif
  360.  
  361. #ifdef DOS
  362.     switch    (_cursvar.adapter)
  363.     {
  364.     case _CGA:    sprintf(_shrtnme, "CGA");      break;
  365.     case _MDA:    sprintf(_shrtnme, "MDA");      break;
  366.     case _EGACOLOR:    sprintf(_shrtnme, "EGAColor"); break;
  367.     case _EGAMONO:    sprintf(_shrtnme, "EGAMono");  break;
  368.     case _VGACOLOR:    sprintf(_shrtnme, "VGAColor"); break;
  369.     case _VGAMONO:    sprintf(_shrtnme, "VGAMono");  break;
  370.     case _MCGACOLOR:sprintf(_shrtnme, "MCGAColor");break;
  371.     case _MCGAMONO:    sprintf(_shrtnme, "MCGAMono"); break;
  372.     case _MDS_GENIUS:sprintf(_shrtnme, "Genius");  break;
  373.     default:    sprintf(_shrtnme, "Unknown");  break;
  374.     }
  375. #endif
  376.  
  377. #ifdef    FLEXOS
  378.     switch    (_cursvar.adapter)
  379.     {
  380.     case _FLEXOS:    sprintf(_shrtnme, "%s", _cursesgname());      break;
  381.     default:    sprintf(_shrtnme, "Unknown");  break;
  382.     }
  383. #endif
  384.  
  385.     return (_shrtnme);
  386. }
  387. /***********************************************************************/
  388. char    wordchar(void)
  389. /***********************************************************************/
  390. {
  391. #ifdef PDCDEBUG
  392.     if (trace_on) PDC_debug("wordchar() - called\n");
  393. #endif
  394.  
  395. #ifdef UNIX
  396. #ifdef USE_TERMIO
  397.     ioctl(_CUR_TERM.fd, TCGETA, &_CUR_TERM.prog_mode);
  398.     return(_CUR_TERM.prog_mode.c_cc[VWERASE]);
  399. #else
  400. #ifdef TIOCGLTC
  401.     ioctl(_CUR_TERM.fd, TIOCGLTC, &_CUR_TERM.prog_mode.bsd_new);
  402.     return(_CUR_TERM.prog_mode.bsd_new.t_werase);
  403. #else
  404.     return(0);
  405. #endif
  406. #endif
  407. #else
  408.     return (_DWCHAR);            /* word delete char */
  409. #endif
  410. }
  411.